package com.yeping.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yeping.domain.ResponseResult;
import com.yeping.domain.entity.BookChapter;
import com.yeping.domain.entity.Chapter;
import com.yeping.mapper.BookChapterMapper;
import com.yeping.mapper.ChapterMapper;
import com.yeping.service.BookChapterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * (BookChapter)表服务实现类
 *
 * @author makejava
 * @since 2024-04-02 21:04:00
 */
@Service("bookChapterService")
public class BookChapterServiceImpl extends ServiceImpl<BookChapterMapper, BookChapter> implements BookChapterService {
    @Autowired
    ChapterMapper chapterMapper;

    @Override
    public ResponseResult getChapters(Long bookId) {
        LambdaQueryWrapper<BookChapter> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(BookChapter::getBookId,bookId);
        List<BookChapter> bcs = list(queryWrapper);
        //由id获得章节信息
        List<Chapter> chapters = bcs.stream()
                .map(bc -> chapterMapper.selectById(bc.getChapterId()))
                .collect(Collectors.toList());
        return ResponseResult.okResult(chapters);
    }
}
